var st = 0,
    lastSt = 0,
    navText = ['<i class="mdi mdi-chevron-left"></i>', '<i class="mdi mdi-chevron-right"></i>'],
    iconspin = '<i class="fa fa-spinner fa-spin"></i> ';

$(document).ready(function () {
    $(".carousel.module").owlCarousel({
        autoHeight: !0,
        dots: !1,
        margin: 30,
        nav: !0,
        navSpeed: 500,
        navText: navText,
        responsive: {
            0: {
                items: 1
            },
            768: {
                items: 3
            },
            992: {
                items: 4
            }
        }
    });

    $(".search-open").on("click", function () {
        $("body").addClass("search-open");
        $(".main-search").find(".search-field").focus();
    });
    $(".search-close").on("click", function () {
        $("body").hasClass("search-open") && $("body").removeClass("search-open")
    });

    slider(), megaMenu(), categoryBoxes(), offCanvas(), sidebar(),
        fancybox(), share_pop(), tap_full();
    $(window).scroll(function () {
        ($("body").hasClass("navbar-sticky") || $("body").hasClass("navbar-sticky_transparent")) && window
            .requestAnimationFrame(navbar)
    });
    $(".header-dropdown").hover(function () {
        $(this).addClass("active")
    }, function () {
        $(this).removeClass("active")
    });
});



function open_signup_popup() {
    var e = $("#popup-signup"),
        t = e.html();
    Swal.fire({
        html: t,
        showConfirmButton: !1,
        width: 340,
        padding: "0",
        focusConfirm: !1,
        onBeforeOpen: () => {
            $(".swal2-container .swal2-input").remove(), $(".swal2-container .swal2-file").remove(), $(
                ".swal2-container .swal2-range").remove(), $(".swal2-container .swal2-select").remove(),
                $(".swal2-container .swal2-radio").remove(), $(".swal2-container .swal2-checkbox").remove(),
                $(".swal2-container .swal2-textarea").remove(), $(
                ".swal2-container .swal2-validation-message").remove(), e.empty()
        },
        onClose: () => {
            e.html(t)
        }
    })
}


function share_pop() {
    $('[etap="share"]').on("click", function () {
        if ($(".article-content img:first").length) var e = $(".article-content img:first").attr("src");
        var t = document.URL,
            a = e,
            n = document.title || "",
            i = $('meta[name="description"]').length ? $('meta[name="description"]').attr("content") : "",
            o = $(this),
            s = "";
        switch (o.data("share")) {
            case "qq":
                s = "http://connect.qq.com/widget/shareqq/index.html?url=" + t + "&desc=" + i + "&summary=" +
                    n + "&site=" + 'huti' + "&pics=" + a;
                break;
            case "weibo":
                s = "http://service.weibo.com/share/share.php?title=" + n + "&url=" + t +
                    "&source=bookmark&pic=" + a
        }
        o.attr("href") || o.attr("target") || o.attr("href", s).attr("target", "_blank")
    })
}


function navbar() {

    st = $(window).scrollTop();
    var e = $(".ads.before_header").outerHeight(),
        t = $(".site-header").height(),
        a = $(".navbar-sticky_transparent.with-hero"),
        n = $(".navbar-sticky.ads-before-header, .navbar-sticky_transparent.ads-before-header"),
        i = $(".navbar-sticky.navbar-slide, .navbar-sticky_transparent.navbar-slide");
    st > t + e ? a.addClass("navbar-sticky") : a.removeClass("navbar-sticky"), st > e ? n.addClass("stick-now") : n
        .removeClass("stick-now"), st > lastSt && st > t + e + 100 ? i.addClass("slide-now") : st + $(window)
        .height() < $(document).height() && i.removeClass("slide-now"), lastSt = st
}

function carousel() {

    $(".carousel.module").owlCarousel({
        autoHeight: !0,
        dots: !1,
        margin: 30,
        nav: !0,
        navSpeed: 500,
        navText: navText,
        responsive: {
            0: {
                items: 1
            },
            768: {
                items: 3
            },
            992: {
                items: 4
            }
        }
    })
}

function slider() {
    var e = {
            autoplay: !0,
            autoplaySpeed: 800,
            loop: !0
        },
        t = $(".slider.big.module"),
        a = {
            animateOut: "fadeOut",
            dots: !0,
            items: 1,
            nav: !1,
            navText: navText
        };
    t.each(function (t, n) {
        if ($(n).hasClass("autoplay")) {
            var i = Object.assign(e, a);
            $(n).owlCarousel(i)
        } else $(n).owlCarousel(a)
    });
    var n = $(".slider.center.module"),
        i = {
            center: !0,
            dotsSpeed: 800,
            loop: !0,
            margin: 20,
            responsive: {
                0: {
                    items: 1
                },
                768: {
                    items: 2
                }
            }
        };
    n.each(function (t, a) {
        if ($(a).hasClass("autoplay")) {
            var n = Object.assign(e, i);
            $(a).owlCarousel(n)
        } else $(a).owlCarousel(i)
    });
    var o = $(".slider.thumbnail.module"),
        s = {
            dotsData: !0,
            dotsSpeed: 800,
            items: 1
        };
    o.each(function (t, a) {
        if ($(a).hasClass("autoplay")) {
            var n = Object.assign(e, s);
            $(a).owlCarousel(n)
        } else $(a).owlCarousel(s)
    })
}

function tap_full() {

    $('[etap="to_full"]').on("click", function () {
        var e = document.documentElement;
        $("body").hasClass("full-screen") ? (console.log(document), $("body").removeClass("full-screen"), $(
            "#alarm-fullscreen-toggler").removeClass("active"), document.exitFullscreen ? document
            .exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document
            .webkitCancelFullScreen ? document.webkitCancelFullScreen() : document.msExitFullscreen &&
            document.msExitFullscreen()) : ($("body").addClass("full-screen"), $(
            "#alarm-fullscreen-toggler").addClass("active"), e.requestFullscreen ? e
            .requestFullscreen() : e.mozRequestFullScreen ? e.mozRequestFullScreen() : e
            .webkitRequestFullscreen ? e.webkitRequestFullscreen() : e.msRequestFullscreen && e
            .msRequestFullscreen())
    })
}

function megaMenu() {

    $(".menu-posts").not(".owl-loaded").owlCarousel({
        items: 5,
        margin: 15
    });
    var e = $(".rollbar");
    $(window).scroll(function () {
        document.documentElement.scrollTop + document.body.scrollTop > 200 ? e.fadeIn() : e.fadeOut()
    }), $('[etap="to_top"]').on("click", function () {
        $("html,body").animate({
            scrollTop: 0
        }, 300)
    }), $(document).on("click", ".tap-dark", function (e) {
        var t = $(this),
            a = t.html();
        t.html(iconspin), toggleDarkMode(), t.html(a)
    })
}

function toggleDarkMode() {
    $("body").toggleClass("ripro-dark")
}

function categoryBoxes() {
    $(".category-boxes").owlCarousel({
        dots: !1,
        margin: 30,
        nav: !0,
        navSpeed: 500,
        navText: navText,
        responsive: {
            0: {
                items: 1
            },
            768: {
                items: 2
            },
            992: {
                items: 3
            },
            1230: {
                items: 4
            }
        }
    })
}

function offCanvas() {

    var e = $(".burger"),
        t = $(".canvas-close");
    $(".main-menu .nav-list").slicknav({
        label: "",
        prependTo: ".mobile-menu"
    }), e.on("click", function () {
        $("body").toggleClass("canvas-opened"), $("body").addClass("canvas-visible"), dimmer("open", "medium")
    }), t.on("click", function () {
        $("body").hasClass("canvas-opened") && ($("body").removeClass("canvas-opened"), dimmer("close", "medium"))
    }), $(".dimmer").on("click", function () {
        $("body").hasClass("canvas-opened") && ($("body").removeClass("canvas-opened"), dimmer("close", "medium"))
    }), $(document).keyup(function (e) {
        27 == e.keyCode && $("body").hasClass("canvas-opened") && ($("body").removeClass("canvas-opened"), dimmer("close",
            "medium"))
    })
}


function sidebar() {

    var e = $(".site-header").height();
    $(window).width() < 768 ? $("aside .widget.widget-pay").insertAfter($("#pay-single-box")) : ($(
        ".container .sidebar-column").theiaStickySidebar({
        additionalMarginTop: e + 0
    }), $(".container .content-column").theiaStickySidebar({
        additionalMarginTop: e + 0
    }))
}

function fancybox() {

    $(function () {
        $('.entry-content a[href*=".jpg"],.entry-content a[href*=".jpeg"],.entry-content a[href*=".png"],.entry-content a[href*=".gif"]')
            .each(function () {
                0 == $(this).parents("a").length && $(this).attr("data-fancybox", "images")
            })
    })
}

function dimmer(e, t) {

    var a = $(".dimmer");
    switch (e) {
        case "open":
            a.fadeIn(t);
            break;
        case "close":
            a.fadeOut(t)
    }
}